<?php
/**
 * Created by PhpStorm.
 * User: gqn
 * Date: 16/5/16
 * Time: 下午10:37
 */

/**
 * 操作日志
 */

function operatelog($operation,$type,$id){
    $user = session('user_auth');
    $maps['uid'] = $user['uid'];
    $maps['name'] = $user['username'];
    $maps['add_time'] = time();
    //操作对象 分类管理
    $maps['operation'] = $operation;
    //1添加2删除3更改
    $maps['type'] = $type;
    //操作的记录id
    $maps['operation_id'] = $id;

    $data = M('log')->add($maps);
    if($data){
        
    }else{
        $array = array('Code'=>403,'msg'=>'操作失败');
        $this->ajaxReturn($array);
    }

}

/**
 * 获取权限字符串
 */

function jur_str($m_id,$a_id){
    if($a_id==1){
        $data['is_update']=1;
        $data['is_delete']=1;
    }else{
        $adminwhere['a_id']=$a_id;
        $admin=M('admin')->where($adminwhere)->find();
        $jur=explode(',',$admin['jurisdiction']);
        $juris='';
        foreach($jur as $j=>$a){
            if(strpos($a,$m_id)){
                $juris=explode('#',$a);
                break;
            }
        }
        $data['is_update']=substr($juris[1],2,1);
        $data['is_delete']=substr($juris[1],4);
    }
    return $data;
}

function pagination($total, $pageSize, $pageIndex)
{
    $page = array();
    $totalPages = ceil($total / $pageSize);
    $pageIndex <= 0 and $pageIndex = 1;
    $offset = ($pageIndex - 1) * $pageSize;

    $page['limit'] = $pageSize;
    $page['offset'] = $offset;
    $page['total'] = (int)$total;//总条目数
    $page['total_pages'] = (int)$totalPages;//总页数
    $page['current_page'] = $pageIndex;//当前页数
    $page['has_nextpage'] = $totalPages > $pageIndex;//是否还有下一页
    return $page;
}

function user_score_sum($uid){

    $sum=D("PScoreRecord")->query('select sum(consume) as consume from zsf_p_score_record where is_deleted=0 and consume>0 and expire_time>='.time().' and type in (1,2,5,6,7) and user_id = '.$uid);
    $sum=$sum[0]['consume'];
    if(empty($sum))
        $sum=0;
    return $sum;
    //积分类型：1报名2导入3兑换4抽奖5分享 6为签到,7为连续签到
}